﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using LsUpdater.API;
using Winform_Setup;
using System.Threading;

namespace LsUpdater
{
    public static class Program
    {

        
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Register reg = new Register();
            Application.EnableVisualStyles();
            CheckRunning(args);          
        }
        private static void CheckRunning(string[] args)
        {
            int ProceedingCount = 0;
            System.Diagnostics.Process[] Processes;
            Processes = System.Diagnostics.Process.GetProcessesByName("updater");

            foreach (System.Diagnostics.Process IsProcedding in Processes)
            {
                if (IsProcedding.ProcessName.Trim().ToLower() == "updater")
                {
                    ProceedingCount += 1;
                }
            }
            if (ProceedingCount > 1)
            {
                DialogResult result;
                result = MessageBox.Show("升级程序已启动!", "升级提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else//启动程序
            {
                if (args.Length != 0)
                {
                    //手动升级                 
                    Application.Run(new loading());
                }
                else
                {
                    //自动检测是否有可用更新                 
                    AutoCheckUpdate checkupdate = new AutoCheckUpdate();                
                }
            }
        }
    }

}
/*
调用示例:
 *第一种:自动检测升级.如果有升级可用,提示让用户选择.可以在form_load里添加
 * System.Diagnostics.Process.Start(System.AppDomain.CurrentDomain.BaseDirectory + @"\Updater.exe"); 
 * 
 * 第二种:手动检测.
 *          string args = "dodiv" + "|" + "dodiv" + "|" + "http://www.zhanzhebian.com/update.xml";
            System.Diagnostics.Process pro = new System.Diagnostics.Process();
            pro.StartInfo.FileName = System.AppDomain.CurrentDomain.BaseDirectory + @"\Updater.exe ";
            pro.StartInfo.UseShellExecute = false;
            pro.StartInfo.Arguments = args;
            pro.Start();
            pro.Close();
*/